function [r] = psnr(o, p)

o = double(o);
p = double(p);
% r = 10 * log10(255 ^ 2 / mean((o(:) - p(:)) .^ 2));

if length(size(o)) == 3
    r = 0;
    for i = 1 : 3
        oo = o(:, :, i);
        pp = p(:, :, i);
        r = r + 10 * log10(255 ^ 2 / mean((oo(:) - pp(:)) .^2 ));
    end
    r = r / 3;
else
    r = 10 * log10(255 ^ 2 / mean((o(:) - p(:)) .^2 ));
end